//
//  MeatShopCartTableViewCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/7/22.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "MeatShopCartTableViewCell.h"

@interface MeatShopCartTableViewCell()


@end

@implementation MeatShopCartTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = KWhiteColor;
        [self setUpView];
    }
    return self;
}


- (void)setUpView{
    
    [self addSubview:self.shopIcon];
    [self addSubview:self.pigTypeLab];
    [self addSubview:self.pigNumLab];
    [self addSubview:self.pigPriceLab];
    [self addSubview:self.pigFailureLab];
    [self addSubview:self.pigCartBtn];
}

- (void)layoutSubviews{
    
    [super layoutSubviews];
    
    _pigTypeLab.text = @"精排";
    _pigNumLab.text = @"HT-02";
    _pigPriceLab.text = @"¥20.56";
    
    
    _shopIcon.mj_x = _shopIcon.mj_y = 15;
    
    //部位
    _pigTypeLab.mj_x = 12 + _shopIcon.right;
    _pigTypeLab.mj_y = 24;

    
    //价格
    _pigPriceLab.mj_x = _pigTypeLab.left;
    _pigPriceLab.mj_y = _pigTypeLab.bottom + 4;
    
    
    //数量
    _pigNumLab.mj_x = _pigTypeLab.right+5;
    _pigNumLab.mj_y = _pigTypeLab.top;
    
    _pigCartBtn.mj_x = KScreenWidth - _pigCartBtn.width - 15;
    _pigCartBtn.mj_y = (self.height - _pigCartBtn.height)/2.0;
    
    CAShapeLayer *line = [CAShapeLayer layer];
    line.fillColor = UIColorFromRGB(0xF2F2F2).CGColor;
    UIBezierPath *path = [UIBezierPath bezierPathWithRect:CGRectMake(15, self.height - 1, KScreenWidth-15, 1)];
    line.path = path.CGPath;
    [self.layer addSublayer:line];
}


#pragma mark - setter and getter
- (void)setIsFailure:(BOOL)isFailure{
    _isFailure = isFailure;
    
    if (isFailure) {
        
        _pigTypeLab.backgroundColor = UIColorFromRGB(0xE9F9F0);
        _pigTypeLab.textColor = mMainColor;
        
        _pigNumLab.textColor = UIColorFromRGB(0x333333);
        
        _pigPriceLab.textColor = UIColorFromRGB(0x848484);
        
        _pigFailureLab.hidden = NO;
        
        [_pigCartBtn setTitle:@"清空" forState:UIControlStateNormal];
        _pigCartBtn.titleLabel.font = mFont(12);
        _pigCartBtn.backgroundColor = UIColorFromRGB(0xAAAAAA);
        [self addShadowAndCircleCorner:_pigCartBtn.layer corner:8.5];
        
    }else{
        _pigTypeLab.backgroundColor = UIColorFromRGB(0xE9F9F0);
        _pigTypeLab.textColor = mMainColor;
        
        _pigNumLab.textColor = UIColorFromRGB(0x333333);
        
        _pigPriceLab.textColor = UIColorFromRGB(0x848484);
        
        _pigFailureLab.hidden = YES;
        
        [_pigCartBtn setTitle:@"nil" forState:UIControlStateNormal];
    }
}
- (UIImageView *)shopIcon{
    if (!_shopIcon) {
        _shopIcon = [[UIImageView alloc] init];
        _shopIcon.size = CGSizeMake(56, 56);
        //_shopIcon.contentMode = UIViewContentModeCenter;
        _shopIcon.image = [UIImage imageNamed:@"p1"];
        [self addShadowAndCircleCorner:_shopIcon.layer corner:8];
        
        [_shopIcon addSubview:self.pigFailureLab];
        _pigFailureLab.center = _shopIcon.center;
    }
    return _shopIcon;
}


//部位
- (UILabel *)pigTypeLab{
    
    if (!_pigTypeLab) {
        _pigTypeLab = [[UILabel alloc] init];
        _pigTypeLab.textColor = mMainColor;
        _pigTypeLab.font = mFont(12);
        _pigTypeLab.backgroundColor = UIColorFromRGB(0xE9F9F0);
        _pigTypeLab.textAlignment = NSTextAlignmentCenter;
        _pigTypeLab.size = CGSizeMake(50, 19);
    }
    return _pigTypeLab;
}

//价格
- (UILabel *)pigPriceLab{
    
    if (!_pigPriceLab) {
        _pigPriceLab = [[UILabel alloc] init];
        _pigPriceLab.font = mFont(12);
        _pigPriceLab.textColor = UIColorFromRGB(0x848484);
        _pigPriceLab.size = CGSizeMake(100, 14);
    }
    return _pigPriceLab;
}


//数量
- (UILabel *)pigNumLab{
    
    if (!_pigNumLab) {
        _pigNumLab = [[UILabel alloc] init];
        _pigNumLab.font = mFont(15);
        _pigNumLab.textColor = UIColorFromRGB(0x333333);
        _pigNumLab.size = CGSizeMake(100, 21);
    }
    return _pigNumLab;
}

//失效标志
- (UILabel *)pigFailureLab{
    
    if (!_pigFailureLab) {
        _pigFailureLab = [[UILabel alloc] init];
        _pigFailureLab.font = mFont(12);
        _pigFailureLab.textColor = KWhiteColor;
        _pigFailureLab.textAlignment = NSTextAlignmentCenter;
        _pigFailureLab.backgroundColor = UIColorFromRGB(0xAAAAAA);
        _pigFailureLab.size = CGSizeMake(35, 17);
        [self addShadowAndCircleCorner:_pigFailureLab.layer corner:_pigFailureLab.height/2.0];
        _pigFailureLab.hidden = YES;
    }
    return _pigFailureLab;
}

- (UIButton *)pigCartBtn{
    if (!_pigCartBtn) {
        _pigCartBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _pigCartBtn.size = CGSizeMake(35, 17);
        [_pigCartBtn setImage:[UIImage imageNamed:@"meat_shopcart_cancel"] forState:UIControlStateNormal];
    }
    return _pigCartBtn;
}


@end
